/**
 * @author David Milne
 */

function QueryResult() {
	//logDebug("QueryResult created");
	
	this.docHash ;
	this.docTitle ;
	this.docName ;
	this.docDescription ;
	
	this.xmlHttp ;
}

QueryResult.prototype.init = queryResult_init ;
QueryResult.prototype.setDetails = queryResult_setDetails ;
QueryResult.prototype.select = queryResult_select ;

function queryResult_init(docTitle, docHash, index) {
	try {
		this.docTitle = docTitle ;
		this.docHash = docHash ;

		this.className = "queryResult" ;
		
		this.docName = document.createElement('div') ;
  		this.docName.className = "name" ;
  		this.docName.innerHTML = docTitle ;
		this.docName.onclick = new Function("koru.queryResultsTray.queryResults[" + index + "].select() ;") ;
  		
  		this.appendChild(this.docName) ;
  
  		this.docDescription = document.createElement('div') ;
  		this.docDescription.className = "description" ;
  		this.docDescription.innerHTML = "loading description.." ; 
  		this.appendChild(this.docDescription) ;	
	} catch (e) {
		logError("queryResult.init.error: " + e ); 
	}
}

function queryResult_setDetails(docDescription, numTerms) {
	try {
		for (var i=0; i < numTerms ; i++) {
			var color = koru.getHighlightColor(i) ;
			
			docDescription = replace(docDescription, "color" + i, color) ;
		}
		this.docDescription.innerHTML = docDescription ;
	} catch (e) {
		logError("queryResult.setDetails.error: " + e ); 
	}
}

function queryResult_select() {
	try {
		koru.documentsTray.openDocument(this.docTitle, this.docHash) ;
	} catch (e) {
		logError("queryResult.select.error: " + e ); 
	}	
}